package seqlist.leetcode;

//删除排序链表中的重复元素
//在一个排序的链表中，存在重复的结点，请删除该链表中重复的结点，重复的结点不保留，返回链表头指针
public class Num82_deleteDuplicates {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode dummyHead =new ListNode(101);
        dummyHead.next=head;
        ListNode prev=dummyHead;
        ListNode cur=prev.next;
        while (cur!=null){
            ListNode next=cur.next;
            if (next==null){
                return dummyHead.next;
            }else{
                if(cur.val==next.val){
                    while (next!=null&&cur.val==next.val){
                        next=next.next;
                    }
                    prev.next=next;
                    cur=next;
                }else {
                    prev=prev.next;
                    cur=cur.next;
                }
            }
        }
        return dummyHead.next;
    }
}
